<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Auth;
class CommonController extends Controller {
    /*
    *自动执行的方法
    */
	public function _initialize()
	{
        $path = MODULE_NAME .'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        // var_dump($path);
        $auth=new Auth();
        if($_SESSION['username']!='admin'){
            if(!$auth->check($path,$_SESSION['id'])){
                $this->success('你没有权限访问',U('admin/login/out'));
                exit;
            };
        } 
	}

    public function returnJson($error=0,$info='什么都没有返回')
    {
        $arr = array(
            'error'=>$error,
            'info'=>$info
            );
        echo  json_encode($arr);
        exit;
    }
    public function log($content,$type=0)
    {
        $data['type']=$type;
        $data['content']=$content;
        $data['username']=$_SESSION['username'];
        $data['ip']=get_client_ip();
        $data['create_time']=time();
        M('log')->add($data);
    }
}